<template>
  <el-dialog
    :key="key"
    v-bind="$attrs"
    v-on="$listeners"
    v-draggable
    :title="title"
    :width="width"
    :visible.sync="show"
    :modal="false"
    :append-to-body="appendToBody"
    :destroy-on-close="true"
    :close-on-click-modal="preferences.DialogModalClick"
    @close="close"
    @closed="closed"
  >
    <template v-if="$slots['default']" slot="default">
      <slot name="default"></slot>
    </template>
    <template v-if="$slots['title']" slot="title">
      <slot name="title"></slot>
    </template>
    <template v-if="$slots['footer']" slot="footer">
      <slot name="footer"></slot>
    </template>
  </el-dialog>
</template>

<script>
import { style } from "@/MUI/style/Style";

export default {
  name: "MDialog",
  data() {
    return {
      key: new Date().getTime(),
      show: false,
    };
  },
  model: {
    prop: "value",
  },
  props: {
    value: {
      type: Boolean,
    },
    width: {
      type: String,
      default: style.$dialogWidth,
    },
    title: {
      type: String,
      default: "",
    },
    appendToBody: {
      type: Boolean,
      default: false,
    },
  },
  components: {},
  watch: {
    value: {
      handler(e) {
        this.show = e;
      },
      immediate: true,
    },
  },
  mounted() {},
  methods: {
    close(e) {
      this.$emit("close", e);
      this.$emit("input", false);
      this.key = new Date().getTime();
    },
    closed(e) {
      this.$emit("closed", e);
    },
  },
};
</script>

<style lang="scss">
@import "../../style/var";
//弹窗
.el-dialog__header:hover {
  cursor: move;
}
</style>
